package com.example.travel.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.travel.domain.entity.Spot;
import com.example.travel.domain.response.SpotUserAndNumber;
import com.example.travel.mapper.SpotMapper;
import com.example.travel.service.SpotService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author : LinQingLiang
 * @file : SpotServiceImpl.java
 * @Since : 2023/2/5 14:15
 */

@Service
public class SpotServiceImpl extends ServiceImpl<SpotMapper, Spot> implements SpotService {

    @Autowired
    private SpotMapper spotMapper;

    @Override
    public Page page(Integer pageNum, Integer pageSize, String name) {

        Page page = new Page(pageNum,pageSize);
        QueryWrapper<Spot> wrapper = new QueryWrapper();
        wrapper.like(name != null && name != "","spot_name",name);
        return spotMapper.page(page,wrapper);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public List<SpotUserAndNumber> userSelectSpot(Integer id) {
        return spotMapper.userSelectSpot(id,"已支付");
    }
}
